/*
visqrt
Copyright (C) 2010  Bhupendra Aole

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
/*
 * File: SaveFileFilter.java
 * Author: Bhupendra Aole
 * Date: Sep 5, 2010: 
 * 
 * Revisions:
 * ----------
 */

package aole.utils;

import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.filechooser.FileFilter;

/**
 * 
 */
public class SaveFileFilter extends FileFilter {

	private String ext[] = ImageIO.getWriterFileSuffixes();
	private static SaveFileFilter ff = null;

	public static SaveFileFilter getInstance () {
		if (ff == null)
			ff = new SaveFileFilter();
		return ff;
	}

	@Override
	public boolean accept (File f) {
		if (f.isDirectory())
			return true;
		String extension = VQUtils.getExtension(f);
		if (extension != null) {
			for (int i = 0; i < ext.length; i++) {
				if (extension.equals(ext[i].toLowerCase()))
					return true;
			}
		}
		return false;
	}

	@Override
	public String getDescription () {
		String d = "";
		for (int i = 0; i < ext.length - 1; i++) {
			d = d + ext[i] + ", ";
		}
		return d + ext[ext.length - 1];
	}
}
